<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width" />
<meta name="format-detection" content="telephone=no" />

<title>aaaa</title>
<link href="http://a7039.s2.cnh.cn/style/activity/css.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="http://a7039.s2.cnh.cn/script/jquery-1.7.2.js"></script>
<script type="text/javascript" src="http://a7039.s2.cnh.cn/script/jquery.form.js"></script>
<script type="text/javascript" src="http://a7039.s2.cnh.cn/script/smart_utils.js"></script>
</head>
<body id="bg2">
<script type="text/javascript">

function showMsg(msg,isError,callBack){
	if(msg){
		// 设置显示高度
		$('#msg').html(msg);
		var noticeTop = (document.documentElement.clientHeight - $("#noticeMessage").height()) * 0.2 + $(document).scrollTop();
		$('#noticeMessage').css("top",noticeTop);
		
		$('#noticeMessage').show();
		
		setTimeout( function(){
			$('#msg').html('');
			$('#noticeMessage').hide();
			if(callBack && typeof(callBack) == "function"){
				callBack();
			}
		} ,3000);
	}
}

function showError(noticeMessage,callBack){
	showMsg(noticeMessage,true,callBack);
}

function showSuccess(noticeMessage, callBack) {
	if(callBack || ""){
		if(typeof(callBack) == "function"){
			showMsg(noticeMessage,false,callBack);
		}else{
			showMsg(noticeMessage,false,function(){
				location.href = callBack;
			});
		}
	}else{
		showMsg(noticeMessage,false);
	}
}

function showTask(msg){
	if(msg || ""){
		$("#wait").find("P").html(msg);
	} else {
		$("#wait").find("P").html("获取中，请稍后！");
	}
	// 设置显示高度
	var waitTop = (document.documentElement.clientHeight - $("#wait").height())  * 0.2 + $(document).scrollTop();
	$('#wait').css("top",waitTop);
	
	$("#wait").show();
	$("#upload_mask").show();
}

function hideTask(){
	$("#wait").hide();
	$("#upload_mask").hide();
}

$(document).ready(function(){
	var noticeMessage = "";

	showMsg(noticeMessage, false);
});


</script>
<img alt="" src="http://a7039.s2.cnh.cn/images/activity/tran_bg2.png" style="display: none;">
<img alt="" src="http://a7039.s2.cnh.cn/images/activity/login_gif.gif" style="display: none;">
<div class="toast_box" style="display: none;" id="wait">
   <div class="toast_1">
    <div class="login_icon"></div>
    <P>获取中，请稍后！</P>
  </div>
</div>

<div class="toast_box" id="noticeMessage" style="display:none;">
   <div class="toast_1">
    <div id="notice_icon"></div>
    <P id="msg"></P>
  </div>
</div>

<div style="display:none;width:100%; height:100%; position:fixed; top:0; left:0; z-index:1001;background:#cccccc; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity:0.5;" id="upload_mask"></div>


<div class="title2">
  <h4 class="title_t1">
  <P>摇一摇</P>
  </h4>
</div>


<div class="shake_img">
  <img src="http://a7039.s2.cnh.cn/images/activity/shake_img.png"/><h4>等待活动开始</h4>
</div>


<div class="button_shake"><a href="javascript:location.reload();" id="btn_result">查看比赛结果>></a></div>
<div style="display:none;">
	<audio src="1.mp3" preload="auto" id="shake_sound" />
</div>

<script type="text/javascript">
(function(){
	/**
	 * 摇一摇
	 * @author rubekid 
	 */
	
	function Shake(options){
		this.init(options);
	}
	
	Shake.prototype = {
		init:function(options){
			options = options || {};
			var x=0, y=0, z=0,_x=0,_z=0,_y=0;
			var t=_t=(new Date()).getTime();		
			if(window.DeviceMotionEvent){
				window.addEventListener("devicemotion", deviceMotionHandler, false);
			}
			else{
				alert("该浏览器不支持摇一摇，请换个浏览器试试！");
			}
			
			function deviceMotionHandler(event){
				t = (new Date()).getTime();
				var diffTime = t - _t;
				if(diffTime < 100){//取时间大于0.1秒的变化
					return ;
				}
								
				var acceleration = event.accelerationIncludingGravity; 
				x = acceleration.x;   
				y = acceleration.y;     
				z = acceleration.z;
				var speed = Math.ceil( Math.abs(( x - _x) + ( y - _y) + ( z - _z )) / diffTime * 100 * 100 );
				
				//保存上一次记录
				_x = x;
				_y = y;
				_z = z;
				_t = t;
				
				if(typeof options.afterShake == "function"){
					options.afterShake(speed, acceleration);
				}
			}
		}
	};

	window.Shake = Shake;
	
})();
$(function(){
	var counter = 0;
	var flag = 0;
	var minY = 10000, maxY = 0;
	var lastY = 0;
	var maxSpeed = 0;
	var shakeSound = document.getElementById("shake_sound");
	
	$(".shake_img").bind("click", function(){
		shakeSound.play();
	});
	var shake = new Shake({
		afterShake:function(speed, acc){
			if(speed > maxSpeed){
				maxSpeed = speed;
			}
			if(lastY > acc.y){
				minY = acc.y;
				flag = 1;
			}
			else{
				if(flag){
					flag = 0;
					if(maxY - minY > 2 && maxSpeed > 2000){
						$(".title_t1").html(maxSpeed);
						counter ++;
						shakeSound.pause();
						shakeSound.currentTime = 0;
						shakeSound.play();
						submitCount(counter);
						maxSpeed = 0; 
					}
				}
				maxY = acc.y;
			}
			lastY = acc.y;
			
		}
	});
	
	
	var xhr = null;
	
	function submitCount(count){
		
	}
});
</script>


<div class="copyright">&nbsp;</div>
</body>
</html>
